package com.dabai.videobrowser.utils;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;


import com.dabai.videobrowser.R;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputLayout;

import java.util.Objects;

/**
 * Description : Other
 *
 * @author BAI
 */
public class OtherUtils {


    public interface OnInputDialog2ButtonListener {
        /**
         * 确认
         *
         * @param dialog   对话框
         * @param content1 content1
         * @param content2 content2
         */
        void confirm(AlertDialog dialog, String content1,String content2);

        /**
         * 取消
         */
        void cancel();

    }

    /**
     * 显示输入对话框
     * 确认时,请手动dismiss
     *
     * @param context                      上下文
     * @param title                        标题
     * @param hint1                        hint1
     * @param hint2                        提示2
     * @param onInputDialog2ButtonListener 在输入dialog2按钮侦听器
     * @return {@link AlertDialog}
     */
    public static AlertDialog showInputDialog2(@NonNull Context context, @NonNull String title,@NonNull String defaultText1,@NonNull String defaultText2, @NonNull String hint1,@NonNull String hint2, OnInputDialog2ButtonListener onInputDialog2ButtonListener) {

        View dialogView = View.inflate(context, R.layout.dialog_rename_rule, null);
        TextView textView = dialogView.findViewById(R.id.titleView);

        TextInputLayout til1 = dialogView.findViewById(R.id.til1);
        til1.setHint(hint1);
        til1.getEditText().setText(defaultText1);

        TextInputLayout til2 = dialogView.findViewById(R.id.til2);
        til2.setHint(hint2);
        til2.getEditText().setText(defaultText2);


        textView.setText(title);

        AlertDialog alertDialog = new MaterialAlertDialogBuilder(context)
                .setView(dialogView)
                .setNeutralButton("取消", (dialog, which) -> onInputDialog2ButtonListener.cancel())
                .setPositiveButton("确认", null).show();

        alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> {
            String content1 = Objects.requireNonNull(til1.getEditText()).getText().toString();
            String content2 = Objects.requireNonNull(til2.getEditText()).getText().toString();
            onInputDialog2ButtonListener.confirm(alertDialog, content1,content2);
        });

        return alertDialog;
    }


}
